package JMU3.hanshu;

/**
 * @author Lenovo
 */
class Fraction{
    private int a;
    private int b;
    public Fraction(int a,int b) {
        if (b < 0) {
            this.b = -b;
            this.a = -a;
        } else {
            this.a = a;
            this.b = b;
        }
    }
        public double toDouble(){
            return (double)a/b;
        }
        Fraction plus(Fraction r){
        Fraction s=new Fraction(0,1);
        s.a=r.a*b+r.b*a;
        s.b=r.b*b;
        return s;

    }
    Fraction multiply(Fraction r){
        Fraction s=new Fraction(0,1);
        s.a=r.a*a;
        s.b=r.b*b;
        return s;

    }

    @Override
    public String toString() {
        int tmp = 0, x = a, y = b;
        if (x < 0)
            x = -x;
        while (x != 0) {
            tmp = y % x;
            y = x;
            x = tmp;
        }
        a /= y;
        b /= y;
        if (a == b)
            return "1";
        else if (a == 0)
            return "0";
        else
            return a + "/" + b;
    }
}